<?php
class MySQLDB
{
    private $conn;
    public $host = '127.0.0.1';
    public $user = 'root';
    public $passwd = '';
    public $dbname = 'test';
    // link database
    function __construct()
    {
        $this->conn = mysqli_connect($this->host, $this->user, $this->passwd, $this->dbname) or die("database link error");
    }
    // 插入数据
    function insert_tables($sql){
        mysqli_query($this->conn, $sql) or die("insert error");
        echo "<font color='green'>告警信息已成功写入到数据库</font><br/>";
    }
    // select data
    function Select($sql)
    {
        $result = mysqli_query($this->conn, $sql);
        $rows = mysqli_fetch_all($result);
        // $rows = mysqli_fetch_assoc($result);
        return $rows;
    }
    //update data
    function Update($sql)
    {
        $result = mysqli_query($this->conn, $sql);
        if ($result == 1) {
            echo "update success", "<br/>";
        } else {
            echo "update error", "<br/>";
        }
    }
    // close database
    function __destruct()
    {
        mysqli_close($this->conn);
    }
}
